package com.rill.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import jdk.nashorn.internal.ir.RuntimeNode.Request;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rill.po.BlogInfo;
import com.rill.service.BlogInfoService;

/**
 * 个性化设置Action：添加
 */
public class EditBlogInfoAction extends ActionSupport {

	// 注入service属性
	private BlogInfoService blogInfoService;

	private String blogtitle;// 标题
	private String idiograph;// 个性设置

	public BlogInfoService getBlogInfoService() {
		return blogInfoService;
	}

	public void setBlogInfoService(BlogInfoService blogInfoService) {
		this.blogInfoService = blogInfoService;
	}

	public String getBlogtitle() {
		return blogtitle;
	}

	public void setBlogtitle(String blogtitle) {
		this.blogtitle = blogtitle;
	}

	public String getIdiograph() {
		return idiograph;
	}

	public void setIdiograph(String idiograph) {
		this.idiograph = idiograph;
	}

	@Override
	public String execute() throws Exception {
		// 业务操作，调用save(),需要BlogInfo，先创建、封装实例
		BlogInfo info = new BlogInfo();
		
		HttpServletRequest request = ServletActionContext.getRequest();
		request.setAttribute("info", "成功");
		/*//动态获取username:方式一：获取session（返回的是httpsession），获取username，
		HttpSession session = request.getSession();
		String username = (String) session.getAttribute("username");
		*/
		
		/*方式二：ActionContext.getContext().getSession()获取session，返的是map*/
		Map session = ActionContext.getContext().getSession();
		String username= (String) session.get("username");
		
		info.setUsername(username);
		/*info.setUsername("张三的歌");// 表单中没有设置，先设置一个*/
		info.setBlogtitle(blogtitle);// 表单传参
		info.setIdiograph(idiograph);

		blogInfoService.saveBlogInfo(info);

		return SUCCESS;
	}

}
